package com.shiguiwu.springboot3.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "members", uniqueConstraints = {
        @UniqueConstraint(columnNames = "username"),
        @UniqueConstraint(columnNames = "email")
})
public class Member {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 50)
    private String username;

    @Column(nullable = false, length = 100)
    private String email;

    @Column(name = "password_hash", nullable = false, length = 255)
    private String passwordHash; // 存储加密后的密码

    @Column(length = 20)
    private String mobile;

    @Column(columnDefinition = "TINYINT DEFAULT 1")
    private Integer status = 1; // 默认状态为1(正常)

    @Column(name = "registration_date", nullable = false, updatable = false)
    private LocalDateTime registrationDate = LocalDateTime.now(); // 默认当前时间

    @Column(name = "last_login_time")
    private LocalDateTime lastLoginTime;

    @Column(name = "avatar_url", length = 255)
    private String avatarUrl;

    @Column(columnDefinition = "json")
    private String extInfo; // 使用String类型存储JSON字符串，也可使用JPA转换器

    // 业务逻辑方法：判断账户是否正常
    public boolean isAccountNonLocked() {
        return this.status != null && this.status == 1;
    }

    public static void main(String[] args) {
    }
}